package com.hlf.modules.merchant.order.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hlf.common.constants.Constants;
import com.hlf.common.constants.FileConstants;
import com.hlf.common.constants.XdLSpdbConstants;
import com.hlf.common.exception.BusinessException;
import com.hlf.common.utils.*;
import com.hlf.common.validator.Assert;
import com.hlf.modules.api.entity.CartEntity;
import com.hlf.modules.api.service.CartService;
import com.hlf.modules.h5.entity.XdLInfo;
import com.hlf.modules.h5.interceptor.AuthorizationInterceptor;
import com.hlf.modules.h5.mapper.XdLInfoMapper;
import com.hlf.modules.merchant.coupon.entity.Coupon;
import com.hlf.modules.merchant.coupon.mapper.CouponMapper;
import com.hlf.modules.merchant.goods.entity.Goods;
import com.hlf.modules.merchant.goods.mapper.GoodsMapper;
import com.hlf.modules.merchant.order.entity.Order;
import com.hlf.modules.merchant.order.entity.OrderDetail;
import com.hlf.modules.merchant.order.mapper.OrderDetailMapper;
import com.hlf.modules.merchant.order.mapper.OrderMapper;
import com.hlf.modules.merchant.order.service.OrderService;
import com.hlf.modules.merchant.store.entity.Store;
import com.hlf.modules.merchant.store.service.StoreService;
import com.hlf.modules.merchant.table.entity.Table;
import com.hlf.modules.merchant.table.service.TableService;
import com.hlf.modules.sys.entity.File;
import com.hlf.modules.sys.entity.SysUserEntity;
import com.hlf.modules.sys.service.FileService;
import com.hlf.modules.wechat.model.Customer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 订单实现类
 * Created by Administrator on 2017/9/22.
 */

@Service("OrderService")
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderDetailMapper orderDetailMapper;
    @Autowired
    private TableService tableService;
    @Autowired
    private StoreService storeService;
    @Autowired
    private CartService cartService;
    @Autowired
    private CouponMapper couponMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private FileService fileService;
    @Autowired
    private XdLInfoMapper xdLInfoMapper;
    @Autowired
    private PropertieUtil propertieUtil;
    protected Logger logger = LoggerFactory.getLogger(getClass());

    /**
     * 分页查询所有订单
     *
     * @param map
     * @return
     */
    @Override
    public PageUtils queryListForPage(Map<String, Object> map) {

        Query query = new Query(map);

        int total = orderMapper.queryTotal(query);
        List<Order> orderList = null;
        if (total > 0) {
            orderList = orderMapper.queryList(query);
        }
        return new PageUtils(orderList, total, query.getLimit(), query.getPage());
    }


    /**
     * 根据门店id查所有订单
     *
     * @param params
     * @return
     */
    @Override
    public PageUtils queryListForStoreId(Map<String, Object> params, Long storeId) {
        Query query = new Query(params);

        int total = orderMapper.queryTotalForStoreId(query, storeId);
        List<Order> orderList = null;
        if (total > 0) {
            orderList = orderMapper.queryListForStoreId(query, storeId);
        }
        return new PageUtils(orderList, total, query.getLimit(), query.getPage());

    }


    /**
     * 根据商家id查所有订单
     *
     * @param params
     * @return
     */
    @Override
    public PageUtils queryListForMerchantId(Map<String, Object> params, Long merchantId) {
        Query query = new Query(params);

        int total = orderMapper.queryTotalForMerchantId(query, merchantId);
        List<Order> orderList = null;
        if (total > 0) {
            orderList = orderMapper.queryListForMerchantId(query, merchantId);
        }
        return new PageUtils(orderList, total, query.getLimit(), query.getPage());
    }

    /**
     * 新增
     *
     * @param order
     * @return
     */
    @Override
    public int insertSelective(Order order) {
        return orderMapper.insertSelective(order);
    }

    /**
     * 查询未完成总订单
     *
     * @param
     * @return
     */
    @Override
    public Order queryForIdUnpaid(Long id) {
        Order order = orderMapper.queryObject(id);
        if (order == null) {
            throw new BusinessException("订单不存在!");
        }
        Byte payStatus = order.getPayStatus();
        if (order.getAddOrderId() == 0 && Constants.ORDER_PAY_STATUS_UNPAID.equals(payStatus)) {
            return order;
        }
        return null;
    }

    /**
     * 根据订单编号 查询未完成的 ,所有订单订单集合
     *
     * @param
     * @return
     */
    @Override
    public List<Order> queryListForOrderNumUnpaid(Long orderNum) {
        List<Order> orders = orderMapper.queryListForOrderNum(orderNum);
        if (orders != null) {
            orders = orders.stream()
                    .filter(order -> Constants.ORDER_PAY_STATUS_UNPAID.equals(order.getPayStatus())).collect(Collectors.toList());
        }
        return orders;
    }

    /**
     * 查询未完成总订单
     *
     * @param tableId
     * @return
     */
    @Override
    public Order queryForTableIdUnpaid(Long tableId) {
        List<Order> orders = orderMapper.queryDepthForTableId(tableId);

        for (Order order : orders) {
            Byte payStatus = order.getPayStatus();
            if (order.getAddOrderId() == 0 && Constants.ORDER_PAY_STATUS_UNPAID.equals(payStatus)) {
                return order;
            }
        }
        return null;
    }

    /**
     * 查找桌位订单数
     *
     * @param tableId
     * @return
     */
    @Override
    public Integer queryCountByTableId(Long tableId) {
        return orderMapper.queryTotalForTableId(tableId);
    }

    /**
     * 返回未完成整个订单(总订单)
     *
     * @param orderDetailList
     * @param tableId
     * @return
     */
    @Transactional
    @Override
    public Order getOrderResultUnpaid(List<OrderDetail> orderDetailList, Long tableId) {
        if (orderDetailList != null) {
            //存储订单详情
            for (OrderDetail orderDetail : orderDetailList) {
                orderDetailMapper.insertSelective(orderDetail);
            }
        }
        List<Order> orders = orderMapper.queryDepthForTableId(tableId);
        for (Order order : orders) {
            Byte payStatus = order.getPayStatus();
            if (order.getAddOrderId() == 0 && Constants.ORDER_PAY_STATUS_UNPAID.equals(payStatus)) {

                Byte couponFlag = order.getCouponFlag();
                String couponName = null;
                //优惠方式
                if (Constants.ORDER_COUPON_FLAG_USE.equals(couponFlag)) {
                    Long couponId = order.getCouponId();
                    Coupon coupon = couponMapper.selectByPrimaryKey(couponId);
                    Integer couponNum = coupon.getCouponNum();
                    Byte couponType = coupon.getCouponType();
                    couponName = Constants.STORE_COUPON_TYPE_REBATE.equals(couponType) ? "整单" + new DecimalFormat("0.0").format
                            (couponNum / 10.0) + " 折" : "整单减免" + new DecimalFormat("0.00").format(couponNum / 100.0) + "元";
                }
                order.setCouponName(couponName);

                //商品名单价
                List<OrderDetail> orderDetails = order.getOrderDetails();
                for (OrderDetail orderDetail : orderDetails) {
                    Goods goods = goodsMapper.queryObjectSimple(Long.parseLong(orderDetail.getGoodsId()));
                    orderDetail.setGoodsName(goods.getName());
                    orderDetail.setOnePrice(goods.getSellPrice());
                }
                order.setOrderDetails(orderDetails);
                return order;
            }
        }

        return null;
    }

    /**
     * 获取未完成订单(加菜订单)
     *
     * @return
     */
    @Override
    public Order getOrderAddUnpaid(Long tableId, Long addOrderId) {
        List<Order> orders = orderMapper.queryDepthForTableId(tableId);
        for (Order order : orders) {
            Byte payStatus = order.getPayStatus();
            if (addOrderId.equals(order.getAddOrderId()) && Constants.ORDER_PAY_STATUS_UNPAID.equals(payStatus)) {
                return order;
            }
        }
        return null;
    }

    /**
     * 将加菜订单汇入总订单,返回深度查询结果
     *
     * @param orderDetailList
     * @param orderResult
     * @return
     */
    @Override
    public Map<String, Object> getOrderAndSaveBranchUnpaid(Long orderIdBranch, List<OrderDetail> orderDetailList, Order orderResult) {
        //总订单id
        Long orderId = orderResult.getId();
        //餐桌id
        Long tableId = orderResult.getTableId();
        //总订单详情
        List<OrderDetail> generalOrderDetails = orderResult.getOrderDetails();
        //总订单id
        Long generalId = orderResult.getId();
        //加菜订单id
        Long addOrderId = orderDetailList.get(0).getAddOrderId();
        //商品总数计数
        Long goodsNum = Long.parseLong(orderResult.getGoodsNum());
        //商品总价计数
        BigDecimal totalAmt = new BigDecimal(orderResult.getTotalAmt());

        //加菜订单汇入总订单
        //遍历加菜订单详情

        for (int i = 0; i < orderDetailList.size(); i++) {
            OrderDetail orderDetail = orderDetailList.get(i);

            String goodsIdBranch = orderDetail.getGoodsId();
            Long orderDetailGoodsNum = orderDetail.getGoodsNum();
            BigDecimal orderDetailAmt = new BigDecimal(orderDetail.getTotalAmt());

            //保存orderId
            orderDetail.setOrderId(String.valueOf(orderIdBranch));
            //菜品相同标志位
            int flag = i;
            //保存加菜订单详情
            orderDetailMapper.insertSelective(orderDetail);
            //遍历总订单订单详情
            for (OrderDetail generalOrderDetail : generalOrderDetails) {
                String goodsId = generalOrderDetail.getGoodsId();

                //如果该菜品总订单也有,则修改数量 价格
                if (goodsId.equals(goodsIdBranch)) {
                    //计数
                    goodsNum = goodsNum + orderDetailGoodsNum;
                    //计价
                    totalAmt = totalAmt.add(orderDetailAmt);
                    //修改标志位
                    flag++;
                    //数量
                    generalOrderDetail.setGoodsNum(generalOrderDetail.getGoodsNum() + orderDetailGoodsNum);
                    //价格
                    BigDecimal generalOrderDetailAmt = new BigDecimal(generalOrderDetail.getTotalAmt());
                    BigDecimal total = generalOrderDetailAmt.add(orderDetailAmt);
                    generalOrderDetail.setTotalAmt(total.intValue());
                    generalOrderDetail.setLastUpdateBy(orderDetail.getLastUpdateBy());
                    //执行修改
                    orderDetailMapper.updateByPrimaryKeySelective(generalOrderDetail);
                }
            }
            //加菜菜品,在总订单内不存在
            if (flag == i) {
                //计数
                goodsNum = goodsNum + orderDetailGoodsNum;
                //计价
                totalAmt = totalAmt.add(orderDetailAmt);
                orderDetail.setId(IdWorkerFactory.nextId());
                orderDetail.setOrderId(String.valueOf(generalId));
                //总订单为0
                orderDetail.setAddOrderId(0L);
                //总订单保存订单详情
                orderDetailMapper.insertSelective(orderDetail);
            }
        }

        // 修改
        Order order = new Order();
        order.setId(orderId);
        order.setGoodsNum(String.valueOf(goodsNum));
        order.setTotalAmt(totalAmt.intValue());
        order.setPayAmt(totalAmt.intValue());
        order.setDiscountAmt(0);
        order.setCouponFlag(Constants.ORDER_COUPON_FLAG_UNABLE);
        order.setCouponId(0L);
        orderMapper.updateByPrimaryKeySelective(order);

        Order generalOrder = getOrderResultUnpaid(null, tableId);
        Order orderAdd = getOrderAddUnpaid(tableId, addOrderId);
        Map<String, Object> map = new HashMap();
        map.put("generalOrder", generalOrder);
        map.put("orderAdd", orderAdd);

        return map;
    }

    /**
     * 创建订单
     *
     * @param request
     * @param tableId
     * @return
     */
    @Transactional
    @Override
    public ReturnResult createOrder(HttpServletRequest request, String tableId) {
        Long tableIdL = Long.parseLong(tableId);
        //判断购物车有无商品
        Boolean isExist = cartService.cartExistGood(tableIdL);
        if (!isExist) {
            return ReturnResult.error("购物车暂无商品!");
        }
        Long userId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY);
        Table table = tableService.queryObjectForId(tableIdL);
        if (table == null) {
            throw new BusinessException("餐桌未找到!");
        }
        Store store = storeService.queryObject(table.getStoreId());
        Order order = new Order();

        //此餐桌是否存在未完成订单
        Integer count = queryCountByTableId(tableIdL);
        if (count > 0) {
            return ReturnResult.error("当前餐桌存在未完成订单!");
        }
        //生成的订单id
        Long orderId = IdWorkerFactory.nextId();
        //用餐人数
        String dinnerNum = null;
        //总金额
        BigDecimal totalAmt = new BigDecimal(0);
        //菜品总数量
        Integer goodsNum = 0;
        //查出购物车
        List<CartEntity> cartEntityList = cartService.queryCartListByTableId(tableIdL);
        List<OrderDetail> orderDetailList = new ArrayList<>();
        for (CartEntity cartEntity : cartEntityList) {
            //订单详情
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setId(IdWorkerFactory.nextId());
            orderDetail.setOrderId(String.valueOf(orderId));
            orderDetail.setGoodsNum(Long.valueOf(cartEntity.getGoodsNum()));
            orderDetail.setGoodsId(String.valueOf(cartEntity.getGoodsId()));
            //计算总价格
            BigDecimal bigDecimalNum = new BigDecimal(cartEntity.getGoodsNum());
            BigDecimal bigDecimalPrice = new BigDecimal(cartEntity.getGoodsPrice());
            BigDecimal goodsAmt = bigDecimalPrice.multiply(bigDecimalNum);
            orderDetail.setTotalAmt(goodsAmt.intValue());
            orderDetail.setLastUpdateBy(userId);
            orderDetailList.add(orderDetail);
            //茶位费
            if (Constants.DEFAULT_TEA_GOODS_TYPE.equals(cartEntity.getGoodsTypeId())) {
                dinnerNum = String.valueOf(cartEntity.getGoodsNum());
            }
            goodsNum = cartEntity.getGoodsNum() + goodsNum;
            //总金额汇总
            totalAmt = totalAmt.add(goodsAmt);
        }
        order.setId(orderId);
        order.setMerchantId(store.getMerchantId());
        order.setMerchantName(store.getMerchantName());
        order.setOrderSource(Constants.ORDER_SOURCE_APP);
        order.setStoreId(store.getId());
        order.setStoreName(store.getName());
        order.setTableId(tableIdL);
        order.setGoodsNum(goodsNum == null ? null : String.valueOf(goodsNum));
        order.setDinnerNum(dinnerNum);
        order.setOprateId(userId);
        order.setCashierName(userId == null ? null : String.valueOf(userId));
        order.setOrderNum(IdWorkerFactory.nextId());
        order.setTotalAmt(totalAmt.intValue());
        order.setPayAmt(totalAmt.intValue());
        order.setPayStatus(Constants.ORDER_PAY_STATUS_UNPAID);
        order.setLastUpdateBy(userId);

        int i = insertSelective(order);
        if (i == 0 || orderDetailList.size() == 0) {
            return ReturnResult.error("订单创建失败!");
        }
        //更新餐桌状态
        table.setLastUpdateBy(userId);
        table.setTableStatus(Constants.TABLE_STATUS_USE);
        int j = tableService.updateByPrimaryKeySelective(table);
        if (j == 0) {
            return ReturnResult.error("订单创建失败!");
        }
        //清空购物车
        cartService.deleteCartByTableId(tableIdL);
        //存储订单详情，深度查找订单
        Order orderResult = getOrderResultUnpaid(orderDetailList, tableIdL);
        //修改库存
        updateRemainQty(orderResult.getOrderDetails());

        /**
         * 1:打印订单给客户
         * 2:打印菜单给后厨
         */
        return ReturnResult.ok();
    }

    /**
     * h5创建订单
     *
     * @param request
     * @param tableId
     * @return
     */
    @Transactional
    @Override
    public ReturnResult h5CreateOrder(HttpServletRequest request, String tableId, Long userId) {
        Long tableIdL = Long.parseLong(tableId);
        //判断购物车有无商品
        Boolean isExist = cartService.cartExistGood(tableIdL);
        if (!isExist) {
            return ReturnResult.error("购物车暂无商品!");
        }

        Table table = tableService.queryObjectForId(tableIdL);
        if (table == null) {
            throw new BusinessException("餐桌未找到!");
        }
        Store store = storeService.queryObject(table.getStoreId());
        Order order = new Order();

        //此餐桌是否存在未完成订单
        Integer count = queryCountByTableId(tableIdL);
        if (count > 0) {
            return ReturnResult.error("当前餐桌存在未完成订单!");
        }
        //生成的订单id
        Long orderId = IdWorkerFactory.nextId();
        //用餐人数
        String dinnerNum = null;
        //总金额
        BigDecimal totalAmt = new BigDecimal(0);
        //菜品总数量
        Integer goodsNum = 0;
        //查出购物车
        List<CartEntity> cartEntityList = cartService.queryCartListByTableId(tableIdL);
        List<OrderDetail> orderDetailList = new ArrayList<>();
        for (CartEntity cartEntity : cartEntityList) {
            //订单详情
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setId(IdWorkerFactory.nextId());
            orderDetail.setOrderId(String.valueOf(orderId));
            orderDetail.setGoodsNum(Long.valueOf(cartEntity.getGoodsNum()));
            orderDetail.setGoodsId(String.valueOf(cartEntity.getGoodsId()));
            //计算总价格
            BigDecimal bigDecimalNum = new BigDecimal(cartEntity.getGoodsNum());
            BigDecimal bigDecimalPrice = new BigDecimal(cartEntity.getGoodsPrice());
            BigDecimal goodsAmt = bigDecimalPrice.multiply(bigDecimalNum);
            orderDetail.setTotalAmt(goodsAmt.intValue());
            orderDetail.setLastUpdateBy(userId);
            orderDetailList.add(orderDetail);
            //茶位费
            if (Constants.DEFAULT_TEA_GOODS_TYPE.equals(cartEntity.getGoodsTypeId())) {
                dinnerNum = String.valueOf(cartEntity.getGoodsNum());
            }
            goodsNum = cartEntity.getGoodsNum() + goodsNum;
            //总金额汇总
            totalAmt = totalAmt.add(goodsAmt);
        }
        order.setId(orderId);
        order.setMerchantId(store.getMerchantId());
        order.setMerchantName(store.getMerchantName());
        order.setOrderSource(Constants.ORDER_SOURCE_WECHAT);
        order.setStoreId(store.getId());
        order.setStoreName(store.getName());
        order.setTableId(tableIdL);
        order.setTableNum(table.getTableNum());
        order.setGoodsNum(goodsNum == null ? null : String.valueOf(goodsNum));
        order.setDinnerNum(dinnerNum);
        order.setMemberId(userId);
        order.setOrderNum(IdWorkerFactory.nextId());
        order.setTotalAmt(totalAmt.intValue());
        order.setPayAmt(totalAmt.intValue());
        order.setPayStatus(Constants.ORDER_PAY_STATUS_UNPAID);
        order.setLastUpdateBy(userId);

        int i = insertSelective(order);
        if (i == 0 || orderDetailList.size() == 0) {
            return ReturnResult.error("订单创建失败!");
        }
        //更新餐桌状态
        table.setLastUpdateBy(userId);
        table.setTableStatus(Constants.TABLE_STATUS_USE);
        int j = tableService.updateByPrimaryKeySelective(table);
        if (j == 0) {
            return ReturnResult.error("订单创建失败!");
        }
        //清空购物车
        cartService.deleteCartByTableId(tableIdL);
        //存储订单详情，深度查找订单
        Order orderResult = getOrderResultUnpaid(orderDetailList, tableIdL);
        //修改库存
        updateRemainQty(orderResult.getOrderDetails());

        /**
         * 1:打印订单给客户
         * 2:打印菜单给后厨
         */
        return ReturnResult.ok();
    }


    /**
     * 创建加菜订单,并合并
     *
     * @param request
     * @param tableId
     * @return
     */
    @Override
    @Transactional
    public ReturnResult addOrder(HttpServletRequest request, String tableId) {

        Long tableIdL = Long.parseLong(tableId);
        //判断购物车有无商品
        Boolean isExist = cartService.cartExistGood(tableIdL);
        if (!isExist) {
            return ReturnResult.error("购物车暂无商品!");
        }
        Long userId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY);
        Table table = tableService.queryObjectForId(tableIdL);
        Store store = storeService.queryObject(table.getStoreId());
        Order order = new Order();

        //查出总订单(未完成)
        Order orderResult = getOrderResultUnpaid(null, tableIdL);

        //生成的订单id
        Long orderId = IdWorkerFactory.nextId();
        //加菜订单id
        Long addOrderId = IdWorkerFactory.nextId();
        //总金额
        BigDecimal totalAmt = new BigDecimal(0);
        //菜品总数量
        Integer goodsNum = 0;
        //查出购物车
        List<CartEntity> cartEntityList = cartService.queryCartListByTableId(tableIdL);
        //存储订单详情
        List<OrderDetail> orderDetailList = new ArrayList<>();
        for (CartEntity cartEntity : cartEntityList) {
            //订单详情
            OrderDetail orderDetail = new OrderDetail();
            orderDetail.setId(IdWorkerFactory.nextId());
            orderDetail.setOrderId(String.valueOf(orderId));
            orderDetail.setAddOrderId(addOrderId);
            orderDetail.setGoodsNum(Long.valueOf(cartEntity.getGoodsNum()));
            orderDetail.setGoodsId(String.valueOf(cartEntity.getGoodsId()));
            //计算总价格
            BigDecimal bigDecimalNum = new BigDecimal(cartEntity.getGoodsNum());
            BigDecimal bigDecimalPrice = new BigDecimal(cartEntity.getGoodsPrice());
            BigDecimal goodsAmt = bigDecimalPrice.multiply(bigDecimalNum);
            orderDetail.setTotalAmt(goodsAmt.intValue());
            orderDetail.setLastUpdateBy(userId);
            orderDetailList.add(orderDetail);

            goodsNum = cartEntity.getGoodsNum() + goodsNum;
            //总金额汇总
            totalAmt = totalAmt.add(goodsAmt);
        }
        order.setId(orderId);
        order.setAddOrderId(addOrderId);
        order.setMerchantId(orderResult.getMerchantId());
        order.setMerchantName(orderResult.getMerchantName());
        order.setOrderSource(Constants.ORDER_SOURCE_APP);
        order.setStoreId(orderResult.getStoreId());
        order.setStoreName(orderResult.getStoreName());
        order.setTableId(tableIdL);
        order.setGoodsNum(goodsNum == null ? null : String.valueOf(goodsNum));
        order.setDinnerNum(orderResult.getDinnerNum());
        order.setOprateId(userId);
        order.setCashierName(userId == null ? null : String.valueOf(userId));
        order.setOrderNum(orderResult.getOrderNum());
        order.setTotalAmt(totalAmt.intValue());
        order.setPayAmt(totalAmt.intValue());
        order.setPayStatus(Constants.ORDER_PAY_STATUS_UNPAID);
        order.setLastUpdateBy(userId);
        int i = insertSelective(order);
        if (i == 0 || orderDetailList.size() == 0) {
            return ReturnResult.error("订单创建失败!");
        }
        //清空购物车
        cartService.deleteCartByTableId(tableIdL);
        //将加菜订单汇入总订单,返回深度查询结果
        Map<String, Object> resulrMap = getOrderAndSaveBranchUnpaid(orderId, orderDetailList, orderResult);

        Order generalOrder = (Order) resulrMap.get("generalOrder");
        //加餐订单
        Order orderAdd = (Order) resulrMap.get("orderAdd");
        //修改库存
        updateRemainQty(orderAdd.getOrderDetails());

        /**
         * 1:打印订单给客户
         * 2:打印菜单给后厨
         */

        return ReturnResult.ok();
    }

    /**
     * 添加备注
     *
     * @param request
     * @param orderId
     * @param remarks
     */
    @Override
    public void insertReamrks(HttpServletRequest request, String orderId, String remarks) {

        Long userId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY);
        Order order = new Order();
        order.setId(Long.parseLong(orderId));
        order.setRemarks(remarks);
        order.setLastUpdateBy(userId);
        int i = orderMapper.updateByPrimaryKeySelective(order);
        if (i == 0) {
            throw new BusinessException("备注添加失败!");
        }
    }

    /**
     * 取消订单
     *
     * @param orderId
     */
    @Transactional
    @Override
    public Long cancelOrder(Customer cust, String orderId) {

        Order orderQuery = orderMapper.queryObject(orderId);

        Byte payStatus = orderQuery.getPayStatus();
        if (Constants.ORDER_PAY_STATUS_CANCEL.equals(payStatus)) {
            throw new BusinessException("订单已取消,不可重复操作!");
        }

        Order order = new Order();
        Long userId = cust.getCustomerId();
        order.setOrderNum(orderQuery.getOrderNum());
        order.setLastUpdateBy(userId);
        order.setPayStatus(Constants.ORDER_PAY_STATUS_CANCEL);
        //执行取消
        int i = orderMapper.updateByOrderNumSelective(order);
        if (i == 0) {
            throw new BusinessException("订单取消失败!");
        }
        //更新餐桌状态
        Long tableId = orderQuery.getTableId();
        Table table = new Table();
        table.setId(tableId);
        table.setLastUpdateBy(userId);
        table.setTableStatus(Constants.TABLE_STATUS_FREE);
        int j = tableService.updateByPrimaryKeySelective(table);
        if (j == 0) {
            throw new BusinessException("订单取消失败!");
        }
        //恢复库存
        List<OrderDetail> orderDetails = orderDetailMapper.selectByOrderId(Long.parseLong(orderId));
        recoverRemainQty(orderDetails);
        return tableId;
    }

    /**
     * 订单详情
     *
     * @param tableId
     * @return
     */
    @Override
    public ReturnResult orderList(String tableId) {
        Order order = getOrderResultUnpaid(null, Long.parseLong(tableId));
        if (order == null) {
            return ReturnResult.ok();
        }
        List<OrderDetail> orderDetails = order.getOrderDetails();
        for (OrderDetail orderDetail : orderDetails) {
            Long id = Long.parseLong(orderDetail.getGoodsId());
            List<File> fileList = fileService.select(FileConstants.GOODS_IMG, id);
            if(fileList.size()>0){
                orderDetail.setFilSerPath(fileList.get(0).getFilSerPath());
            }
        }
        Assert.isNull(order, "订单未找到!");
        return ReturnResult.ok().put(Constants.DEFAULT_RESULT_NAME, order);
    }

    /**
     * 转台
     *
     * @param request
     * @param newTableId
     * @param orderId
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void changTable(HttpServletRequest request, String newTableId, String orderId) {

        //校验新餐桌有无未完成订单
        Byte tableStatus = tableService.queryObjectForId(Long.parseLong(newTableId)).getTableStatus();
        if (!Constants.TABLE_STATUS_FREE.equals(tableStatus)) {
            throw new BusinessException("当前餐桌已经有人使用!");
        }
        Order orderQuery = orderMapper.queryObject(orderId);
        Order order = new Order();
        Long oldTableId = orderQuery.getTableId();
        Long userId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY);
        order.setOrderNum(orderQuery.getOrderNum());
        order.setLastUpdateBy(userId);
        order.setTableId(Long.parseLong(newTableId));
        order.setOldTableId(oldTableId);
        //执行转台
        int i = orderMapper.updateByOrderNumSelective(order);
        if (i == 0) {
            throw new BusinessException("转台失败!");
        }

        //更新餐桌状态
        Table table = new Table();
        table.setId(oldTableId);
        table.setLastUpdateBy(userId);
        table.setTableStatus(Constants.TABLE_STATUS_FREE);
        int j = tableService.updateByPrimaryKeySelective(table);
        if (j == 0) {
            throw new BusinessException("转台失败!");
        }
        table.setId(Long.parseLong(newTableId));
        table.setTableStatus(Constants.TABLE_STATUS_USE);
        int k = tableService.updateByPrimaryKeySelective(table);
        if (k == 0) {
            throw new BusinessException("转台失败!");
        }
    }

    /**
     * 打折优惠
     *
     * @param id
     * @param orderId
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void rebate(HttpServletRequest request, String id, String orderId) {
        Order order = queryForIdUnpaid(Long.parseLong(orderId));
        Long userId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY);
        rebateReckon(userId, Long.parseLong(id), order);
    }

    /**
     * 退菜
     *
     * @param request
     * @param orderId
     * @param goodsId
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void returnGoods(HttpServletRequest request, String orderId, String goodsId) {

        //根据订单id和商品id查订单详情中的商品
        OrderDetail orderDetail = orderDetailMapper.selectByOrderIdAndGoodsId(Long.parseLong(orderId), Long.parseLong(goodsId));
        //查出订单信息
        Order order = orderMapper.queryObject(Long.parseLong(orderId));

        Long userId = (Long) request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY);
        //修改订单总价格
        BigDecimal orderTotalAmt = new BigDecimal(order.getTotalAmt());
        BigDecimal goodsTotalAmt = new BigDecimal(orderDetail.getTotalAmt());
        orderTotalAmt = orderTotalAmt.subtract(goodsTotalAmt);
        order.setTotalAmt(orderTotalAmt.intValue());
        order.setPayAmt(orderTotalAmt.intValue());
        //修改商品总数量
        Long goodsNum = orderDetail.getGoodsNum();
        String orderGoodsNum = order.getGoodsNum();
        orderGoodsNum = String.valueOf(Long.parseLong(orderGoodsNum) - goodsNum);
        order.setGoodsNum(orderGoodsNum == null ? "0" : orderGoodsNum);
        order.setLastUpdateBy(userId);
        //更改优惠券信息
        order.setCouponFlag(Constants.ORDER_COUPON_FLAG_UNABLE);
        order.setCouponId(0L);
        order.setDiscountAmt(0);

        int j = orderDetailMapper.deleteByPrimaryKey(orderDetail.getId());
        int i = orderMapper.updateByPrimaryKeySelective(order);
        if (j == 0 || i == 0) {
            throw new BusinessException("退菜失败!");
        }

        /**
         * 需打印小票 ,通知后厨
         */
    }

    /**
     * 计算优惠
     *
     * @param userId
     * @param id     优惠券id
     * @param order
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void rebateReckon(Long userId, Long id, Order order) {
        Coupon coupon = couponMapper.selectByPrimaryKey(id);
        Store store = storeService.queryObject(order.getStoreId());
        if (coupon == null) {
            throw new BusinessException("优惠券未找到!");
        }
        //总价
        BigDecimal totalAmt = new BigDecimal(order.getTotalAmt());
        BigDecimal payAmt;
        //校验最低消费
        BigDecimal spendMin = new BigDecimal(coupon.getSpendMin());
        int j = totalAmt.compareTo(spendMin);
        if (j < 0) {
            throw new BusinessException("不符合该优惠券使用要求!");
        }
        if (Constants.STORE_COUPON_STATUS_CLOSE.equals(store.getStoreCouponStatus())) {
            throw new BusinessException("本店暂时不能使用优惠券!");
        }
        if (Constants.ORDER_COUPON_FLAG_USE.equals(order.getCouponFlag())) {
            throw new BusinessException("已使用过优惠券,不可重复使用!");
        }
        BigDecimal couponNum;
        Integer couponNumInt = coupon.getCouponNum();
        //优惠方式
        Byte couponType = coupon.getCouponType();
        if (Constants.STORE_COUPON_TYPE_REBATE.equals(couponType)) {
            //打折
            couponNum = new BigDecimal(couponNumInt / 100.0).setScale(2, RoundingMode.HALF_UP);
            payAmt = totalAmt.multiply(couponNum).setScale(0, RoundingMode.HALF_UP);
        } else if (Constants.STORE_COUPON_TYPE_MINUS.equals(couponType)) {
            //整单减免
            couponNum = new BigDecimal(couponNumInt);
            //比较总价和优惠额
            int i = totalAmt.compareTo(couponNum);
            if (i <= 0) {
                throw new BusinessException("优惠不可大于总价!");
            }
            //执行优惠
            payAmt = totalAmt.subtract(couponNum);
        } else {
            throw new BusinessException("优惠方式出错!");
        }

        //存入订单
        order.setPayAmt(payAmt.intValue());
        order.setDiscountAmt(totalAmt.subtract(payAmt).intValue());  //优惠钱数
        order.setCouponFlag(Constants.ORDER_COUPON_FLAG_USE);
        order.setLastUpdateBy(userId);
        order.setCouponId(id);
        int i = orderMapper.updateByPrimaryKeySelective(order);
        if (i == 0) {
            throw new BusinessException("使用优惠券失败!");
        }
    }

    /**
     * 打印小票
     *
     * @param tableId
     */
    @Override
    public void print(String tableId) {
        Order order = getOrderResultUnpaid(null, Long.parseLong(tableId));
        Boolean b = printList(order);
        if (!b) {
            throw new BusinessException("打印异常!");
        }
    }

    /**
     * 执行打印
     *
     * @param order
     */
    public Boolean printList(Order order) {

        /**
         * 检查打印机是否连接
         */

        return null;
    }

    /**
     * 现金收款
     *
     * @param orderId
     */
    @Override
    @Transactional
    public void cashPay(Customer cust, String orderId) {
        Long userId = cust.getCustomerId();
        paySuccess(userId, Long.parseLong(orderId), Constants.ORDER_PAY_TYPE_MONEY);
    }

    /**
     * 现金付款成功
     *
     * @param userId
     * @param orderId
     */
    public void paySuccess(Long userId, Long orderId, Byte type) {
        Order order = queryForIdUnpaid(orderId);
        if (order == null) {
            throw new BusinessException("未找到该订单!");
        }
        Date date = new Date();
        //更改总订单和加菜订单 支付状态
        order.setPayStatus(Constants.ORDER_PAY_STATUS_OK);
        order.setPayType(type);
        order.setLastUpdateBy(userId);
        order.setPayTime(date);
        order.setLastUpdateDate(date);
        orderMapper.updateByPrimaryKeySelective(order);
        //释放餐桌状态
        Long tableId = order.getTableId();
        if (tableId == null) {
            throw new BusinessException("未找到用餐餐桌!");
        }
        Table table = new Table();
        table.setId(tableId);
        table.setTableStatus(Constants.TABLE_STATUS_FREE);
        table.setLastUpdateDate(date);
        tableService.updateByPrimaryKeySelective(table);
    }

    /**
     * 一码支付
     *
     * @param request
     * @param orderId
     */
    @Override
    public void ymPay(HttpServletRequest request, String orderId) {


    }

    /**
     * 订单列表(根据订单状态分类)
     *
     * @param storeId
     * @return
     */
    @Override
    public Map<Byte, List<Order>> queryOrderByStoreId(String storeId) {

        List<Order> orderList = orderMapper.queryDepthForStoreId(Long.parseLong(storeId));
        List<Order> orderResult = new ArrayList<>(orderList.size());

        for (Order order : orderList) {
            List<OrderDetail> orderDetails = order.getOrderDetails();
            for (OrderDetail orderDetail : orderDetails) {
                Goods goods = goodsMapper.queryObjectSimple(Long.parseLong(orderDetail.getGoodsId()));
                orderDetail.setGoodsName(goods.getName());
                orderDetail.setOnePrice(goods.getSellPrice());

                order.setOrderDetails(orderDetails);
            }
            orderResult.add(order);
        }
        Map<Byte, List<Order>> map = orderResult.stream().filter(order -> order.getAddOrderId() == 0).collect(Collectors.groupingBy(Order::getPayStatus));
        if (!map.containsKey(Constants.ORDER_PAY_STATUS_UNPAID)) {
            map.put(Constants.ORDER_PAY_STATUS_UNPAID, null);
        }
        if (!map.containsKey(Constants.ORDER_PAY_STATUS_OK)) {
            map.put(Constants.ORDER_PAY_STATUS_OK, null);
        }
        if (!map.containsKey(Constants.ORDER_PAY_STATUS_FAIL)) {
            map.put(Constants.ORDER_PAY_STATUS_FAIL, null);
        }
        if (!map.containsKey(Constants.ORDER_PAY_STATUS_CANCEL)) {
            map.put(Constants.ORDER_PAY_STATUS_CANCEL, null);
        }

        return map;
    }

    /**
     * 订单搜索
     *
     * @param tableNum
     * @param storeId
     * @return
     */
    @Override
    public List<Order> orderSerach(String tableNum, String storeId) {
        List<Table> tables = tableService.serachByTableNum(tableNum, Long.parseLong(storeId));
        if (tables == null) {
            return null;
        }
        List<Order> orderList = new ArrayList<>();
        for (Table table : tables) {
            Order order = queryForTableIdUnpaid(table.getId());
            if (order == null) {
                continue;
            }
            orderList.add(order);
        }
        return orderList;
    }

    /**
     * 免茶位费
     *
     * @param tableId
     * @param currentStoreId
     * @param user
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void gratisTea(String tableId, String currentStoreId, SysUserEntity user) {

        Order order = queryForTableIdUnpaid(Long.parseLong(tableId));
        if (order == null) {
            throw new BusinessException("无订单!");
        }
        //查处本店茶位费商品
        List<Goods> teas = goodsMapper.queryByOrderIdAndTeaType(order.getStoreId(), Constants.DEFAULT_TEA_GOODS_TYPE);
        Goods tea = teas.get(0);
        //查询订单详情
        OrderDetail orderDetail = orderDetailMapper.queryByGoodsIdAndOrderId(tea.getId(), order.getId());
        //已删除
        if (Constants.DELETE_FLAG_UNABLE.equals(orderDetail.getDelFlag())) {
            throw new BusinessException("已免过茶味啦,请不要重复操作!");
        }
        //修改数量
        order.setGoodsNum(String.valueOf(Long.valueOf(order.getGoodsNum()) - orderDetail.getGoodsNum()));
        order.setCouponFlag(Constants.ORDER_COUPON_FLAG_UNABLE);
        BigDecimal totalAmt = new BigDecimal(order.getTotalAmt());
        BigDecimal teaTotalAmt = new BigDecimal(orderDetail.getTotalAmt());
        BigDecimal newTotalAmt = totalAmt.subtract(teaTotalAmt);
        order.setTotalAmt(newTotalAmt.intValue());
        order.setDiscountAmt(null);
        order.setPayAmt(newTotalAmt.intValue());
        order.setCouponId(null);
        order.setLastUpdateDate(new Date());
        order.setLastUpdateBy(user.getUserId());
        int i = orderMapper.updateByPrimaryKey(order);
        orderDetail.setDelFlag(Constants.DELETE_FLAG_UNABLE);
        int j = orderDetailMapper.updateByPrimaryKeySelective(orderDetail);
        if (i == 0 || j == 0) {
            throw new BusinessException("操作失败!");
        }

    }


    /**
     * 今日详情
     *
     * @param user
     * @return
     */
    @Override
    public ReturnResult today(SysUserEntity user) {

        BigDecimal todayAmt = new BigDecimal(0);

        String storeId = user.getCurrentStoreId();
        List<Order> orderList = orderMapper.queryListByStoreIdAndToday(storeId);

        //筛选出已完成订单
        orderList = orderList.stream().filter(order -> Constants.ORDER_PAY_STATUS_OK.equals(order.getPayStatus())
                && order.getAddOrderId() == 0).collect(Collectors.toList());

        for (Order order : orderList) {
            BigDecimal payAmt = new BigDecimal(order.getPayAmt());
            todayAmt = todayAmt.add(payAmt);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("orderNum", orderList.size());
        map.put("sales", todayAmt.intValue());

        return ReturnResult.ok().put(Constants.DEFAULT_RESULT_NAME, map);
    }

    /**
     * h5根据userid查订单列表
     *
     * @param userId
     * @return
     */
    @Override
    public List<Order> h5QueryListByUserId(Long userId) {
        List<Order> orderList = orderMapper.queryListByUserId(userId);
        return orderList;
    }

    /**
     * 更改库存
     */
    public void updateRemainQty(List<OrderDetail> orderDetailsList) {
        if (orderDetailsList == null) {
            return;
        }
        for (OrderDetail orderDetail : orderDetailsList) {
            String goodsId = orderDetail.getGoodsId();
            Goods goods = goodsMapper.queryObject(Long.parseLong(goodsId));

            int qty = goods.getRemainQty() - orderDetail.getGoodsNum().intValue();
            if (qty <= 0) {
                goods.setStatus(Constants.GOODS_STATUS_NOONE);
                goods.setRemainQty(0);
            } else {
                goods.setRemainQty(qty);
            }
            goods.setLastUpdateDate(new Date());
            goodsMapper.updateByPrimaryKeySelective(goods);
        }
    }

    /**
     * 取消订单,恢复库存
     */
    public void recoverRemainQty(List<OrderDetail> orderDetailsList) {

        if (orderDetailsList == null) {
            return;
        }
        for (OrderDetail orderDetail : orderDetailsList) {
            String goodsId = orderDetail.getGoodsId();
            Goods goods = goodsMapper.queryObject(Long.parseLong(goodsId));
            int qty = goods.getRemainQty() + orderDetail.getGoodsNum().intValue();
            if (qty > 0) {
                goods.setRemainQty(qty);
                goods.setStatus(Constants.GOODS_STATUS_SHELVE);
                goods.setLastUpdateDate(new Date());
                goodsMapper.updateByPrimaryKeySelective(goods);
            }
        }
    }

    /**
     * 查询公众号和微信支付
     *
     * @param customer
     * @return
     * @throws Exception
     */
    @Override
    @Transactional
    public Map<String, Object> executePayRequest(Customer customer, String orderId) throws Exception {

        //需要token和订单id
        Order order = orderMapper.queryObject(orderId);
        Long storeId = order.getStoreId();
        XdLInfo xdLInfo = xdLInfoMapper.selectByPrimaryKey(storeId);
        if (xdLInfo == null || xdLInfo.getKey() == null) {
            throw new BusinessException("商户未审核不能支付!");
        }
        if (order == null) {
            throw new BusinessException("订单不存在!");
        }
        if (Constants.ORDER_PAY_STATUS_OK.equals(order.getPayStatus())) {
            throw new BusinessException("订单已付款!");
        }
        String flag = propertieUtil.getPropertie("PAY_REDIRECT_FLAG_WECHAT");
        String orderIdStr = flag + orderId.toString();
        String key = xdLInfo.getKey();
        String mchNo = xdLInfo.getMercId();
        String openId = customer.getOpenId();
        String trmNo = xdLInfo.getTrmNo();
        String merchantName = order.getMerchantName();
        String payAmt = order.getPayAmt().toString();
        JSONObject objApp = new JSONObject();
        objApp.put("orgNo", XdLSpdbConstants.REPORT_ORGNO);  //  //   1   String  6   机构号 合作商机构号
        objApp.put("mercId", mchNo); // 1 String Max(15) 商户号
        objApp.put("trmNo", trmNo); //1 String Max(8) 设备号 长度8位数字，进件生成终端号
        objApp.put("txnTime", DateUtil.dateToString(new Date(), DateUtil.DateStyle.YYYYMMDDHHMMSS)); //1 String Max(14)设备端交易时间如：20170527153245
        objApp.put("version", "V1.0.0"); //1 String Max(10) 版本号 默认V1.0.0
        objApp.put("signType", "MD5"); //1 String Max(13)授权code 在授权回调页面中获取到的授权code
        String string1 = "";
        Collection<String> keyset = objApp.keySet();
        List list = new ArrayList<String>(keyset);
        Collections.sort(list);
        //这种打印出的字符串顺序和微信官网提供的字典序顺序是一致的
        for (int i = 0; i < list.size(); i++) {
            string1 = string1 + objApp.get(list.get(i));
        }
        String do_sign = string1 + key;
        logger.info("do_sign: {}", do_sign);
        //md5加密 并转成小写
        String sign = MD5Util.MD5Encode(do_sign, "utf-8").toLowerCase(); //
        logger.info("sign: {}", sign);
        objApp.put("signValue", sign);// MD5加密
        logger.info("公众号查询请求参数 reqStr = {}", objApp);
        String content = objApp.toString();
        String response = RESTfulSDLHttpUtils.sendPost(XdLSpdbConstants.WECHAT_PAY_QUERY_URL, content);
        logger.info("公众号查询上游返回: {}", response);
        JSONObject json = JSONObject.parseObject(response);
        String code = json.getString("returnCode");
        String reString = json.getString("message");
        logger.info("公众号查询上游返回code: {}", code);
        logger.info("公众号查询上游返回message: {}", reString);

        JSONObject obj = new JSONObject();
        obj.put("orgNo", XdLSpdbConstants.REPORT_ORGNO);  //  //   1   String  6   机构号 合作商机构号
        obj.put("mercId", mchNo); // 1 String Max(15) 商户号
        obj.put("trmNo", trmNo); //1 String Max(8) 设备号 长度8位数字，进件生成终端号
        obj.put("txnTime", DateUtil.dateToString(new Date(), DateUtil.DateStyle.YYYYMMDDHHMMSS)); //1 String Max(14)设备端交易时间如：20170527153245
        obj.put("version", "V1.0.0"); //1 String Max(10) 版本号 默认V1.0.0
        obj.put("openid", openId); //1 String Max(13)授权code 在授权回调页面中获取到的授权code
        obj.put("amount", payAmt); //1 String Max(13)实付金额以分为单位，如1元表示为100
        obj.put("total_amount", payAmt); // 1 String Max(13) 订单总金额 以分为单位， 如1元表示为100

        String string2 = "";
        Collection<String> keyset1 = obj.keySet();
        List list1 = new ArrayList<String>(keyset1);
        Collections.sort(list1);
        //这种打印出的字符串顺序和微信官网提供的字典序顺序是一致的
        for (int i = 0; i < list1.size(); i++) {
            string2 = string2 + obj.get(list1.get(i));
        }
        String do_sign1 = string2 + key;
        logger.info("do_sign: {}", do_sign1);
        //md5加密 并转成小写
        String sign1 = MD5Util.MD5Encode(do_sign1, "utf-8").toLowerCase(); //
        logger.info("sign: {}", sign1);
        obj.put("subject", merchantName == null ? "商品" : merchantName); // 0 String Max(256) 订单标题
        obj.put("selOrderNo",orderIdStr); //0 String Max(50)订单号 订货订单号
        obj.put("signValue", sign1);// MD5加密
        logger.info("支付请求参数 reqStr = {}", obj);
        String content1 = obj.toString();
        String response1 = RESTfulSDLHttpUtils.sendPost(XdLSpdbConstants.WECHAT_PAY_URL, content1);
        logger.info("上游返回: {}", response1);
        JSONObject json1 = JSONObject.parseObject(response1);
        String code1 = json1.getString("returnCode");
        String reString1 = json1.getString("message");
        String result = "";
        try {
            if (null != reString1) {
                result = java.net.URLDecoder.decode(reString1, "utf-8");
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if ("000000".equals(code1)) {
            Map<String, Object> map = new HashMap<>();
            String apiAppid = json1.getString("apiAppid");
            String apiTimestamp = json1.getString("apiTimestamp");
            String apiNoncestr = json1.getString("apiNoncestr");
            String apiPackage = json1.getString("apiPackage");
            String apiSigntype = json1.getString("apiSigntype");
            String apiPaysign = json1.getString("apiPaysign");
            map.put("appId", apiAppid);
            map.put("timeStamp", apiTimestamp);
            map.put("signType", apiSigntype);
            map.put("package", apiPackage);
            map.put("nonceStr", apiNoncestr);
            map.put("paySign", apiPaysign);
            logger.info("支付接口返回支付页面参数: {}", map);
            return map;
        } else {
            throw new BusinessException(result);
        }
    }

    @Override
    public Order queryOrderBytableId(String tableId) {
        return orderMapper.queryOrderByTableId(tableId);
    }

    @Override
    public Order queryObject(String orderId) {
        return orderMapper.queryObject(orderId);
    }


}
